<?php
/**
 * 全要素分析首页
 * Created by PhpStorm.
 * User: yy
 * Date: 2019/4/17
 * Time: 11:07
 */

namespace app\api\controller;

use app\common\service\environmentAnalysis\EnvironmentAnalysisService;
use app\common\validate\environmentAnalysis\EnvironmentAnalysisValidate;


class EnvironmentAnalysis extends BaseController
{
    /**
     * 获取SO2或NOX或烟尘的不同行业排放量(暂时取消烟尘)
     * @author yy by 2019/4/17
     */
    public function getIndustryEmission()
    {
        $param = $this->request->param();
        # 模拟数据
//        $param    = ['start_time' => '2019-02-01', 'end_time' => '2019-05-01', 'contribution_name' => 'smoke_dust' ,'region_id' =>53, 'station_id'=>0];
        $validate = new EnvironmentAnalysisValidate();
        $result   = $validate->check($param, [], 'industryEmission');
        if (!$result) {
            $this->error($validate->getError());
        }
        $list = [];
        try {
            $companyIndustryMonitorSimulationDayService = new EnvironmentAnalysisService();
            $list                                       = $companyIndustryMonitorSimulationDayService->getIndustryEmission($param);
        } catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('成功', $list);
    }

    /**
     * 行业排放趋势(默认电力供热行业)(暂时取消烟尘)
     * （烟尘）行业贡献度趋势需要和气象局提供相关数据 目前只有SO2,NOX(NO2) TODO
     * @author yy by 2019/4/17
     */
    public function getIndustryEmissionTrend()
    {
        $param = $this->request->param();
        # 模拟数据
//        $param    = ['start_time' => '2019-04-01', 'end_time' => '2019-04-05', 'company_pollutant_name' => 'so2', 'trend_type' => 'emission', 'industry_id' => 1, 'region_id'=>53, 'station_id'=>1];
        $validate = new EnvironmentAnalysisValidate();
        $result   = $validate->check($param, [], 'industryEmissionTrend');
        if (!$result) {
            $this->error($validate->getError());
        }
        $list = [];
        try {
            $companyIndustryMonitorSimulationDayService = new EnvironmentAnalysisService();
            $list                                       = $companyIndustryMonitorSimulationDayService->getIndustryEmissionTrend($param);
        } catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('成功', $list);
    }

    /**
     * 行业贡献度趋势
     * @author yy by 2019/5/25
     */
    public function getIndustryContributeTrend()
    {
        $param = $this->request->param();
        # 模拟数据
//        $param  = ['start_time' => '2019-04-30 00:00:00', 'end_time' => '2019-05-31 00:00:00','contribute_pollutant_name' => 'no2', 'industry_id'=>1, 'region_id'=>53, 'station_id'=>1];
        $validate = new EnvironmentAnalysisValidate();
        $result   = $validate->check($param, [], 'industryContributeTrend');
        if (!$result) {
            $this->error($validate->getError());
        }
        $list = [];
        try {
            $companyIndustryMonitorSimulationDayService = new EnvironmentAnalysisService();
            $list                                       = $companyIndustryMonitorSimulationDayService->getIndustryContributeTrend($param);
        } catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('成功', $list);
    }
    /**
     * 获取全市AQI趋势图(目前是长治市)(暂时取消烟尘)
     * @author yy by 2019/4/18
     */
    public function getAqiTrend()
    {
        $param = $this->request->param();
        # 模拟数据
//        $param    = ['start_time' => '2019-5-1', 'end_time' => '2019-5-18','region_id'=>53, 'station_id'=>0];
//        $param    = ['start_time' => '2019-05-01', 'end_time' => '2019-05-18','region_id'=>53, 'station_id'=>0];
        $validate = new EnvironmentAnalysisValidate();
        $result   = $validate->check($param, [], 'aqiTrend');
        if (!$result) {
            $this->error($validate->getError());
        }
        $list = [];
        try {
            $companyIndustryMonitorSimulationDayService = new EnvironmentAnalysisService();
            $list                                       = $companyIndustryMonitorSimulationDayService->getAqiTrend($param);
        } catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('成功', $list);
    }

    /**
     * 获取污染物天数占比
     * 当天之前查实测表，当天和之后查预报表
     * @author yy by 2019/4/19
     */
    public function getPollutantDay()
    {
        $param = $this->request->param();
        # 模拟数据
//        $param    = ['start_time' => '2019-04-01', 'end_time' => '2019-05-30','region_id'=>53, 'station_id'=>0];
        $validate = new EnvironmentAnalysisValidate();
        $result   = $validate->check($param, [], 'pollutantDay');
        if (!$result) {
            $this->error($validate->getError());
        }
        $list = [];
        try {
            $companyIndustryMonitorSimulationDayService = new EnvironmentAnalysisService();
            $list                                       = $companyIndustryMonitorSimulationDayService->getPollutantDay($param);
        } catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('成功', $list);
    }

    /**
     * 获取首要污染物占比(默认aqi_level轻度)
     * 当天之前查实测表，当天和之后查预报表
     * @author yy by 2019/4/19
     */
    public function getPrimaryPollutant()
    {
        $param = $this->request->param();
        # 模拟数据
//        $param    = ['start_time' => '2019-05-28', 'end_time' => '2019-06-06','region_id'=>53, 'station_id'=>0, 'aqi_level'=>'轻度'];
        $validate = new EnvironmentAnalysisValidate();
        $result   = $validate->check($param, [], 'primaryPollutant');
        if (!$result) {
            $this->error($validate->getError());
        }
        $list = [];
        try {
            $companyIndustryMonitorSimulationDayService = new EnvironmentAnalysisService();
            $list                                       = $companyIndustryMonitorSimulationDayService->getPrimaryPollutant($param);
        } catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('成功', $list);
    }

}